package com.hjl.sr.security.token;

import com.hjl.sr.security.token.store.TokenStoreService;

public class TokenServiceImpl implements TokenService {
	
	static final int TOKEN_EXPIRE = 60 * 5; // 5分钟
	
	private TokenStoreService tokenStoreService;
	
	private TokenGenerator tokenGenerator;

	public TokenServiceImpl(TokenStoreService tokenStoreService, TokenGenerator tokenGenerator) {
		super();
		this.tokenStoreService = tokenStoreService;
		this.tokenGenerator = tokenGenerator;
	}

	public String getToken() {
		String token = tokenGenerator.getNextToken();
		tokenStoreService.set(token, TOKEN_EXPIRE);
		return token;
	}

}
